#include "CyMessageProcessor.h"
#include "CyRoutine.h"
using namespace std;

CyMessageProcessor::FilterList CyMessageProcessor::_filterList;

BOOL CyMessageProcessor::ProcessMessage(HWND hWnd,
	UINT message, WPARAM wParam, LPARAM lParam)
{
	BOOL result = FALSE;

	for (FilterList::iterator i = _filterList.begin(); 
		i != _filterList.end(); i++) 
	{
		result = result || (*i)->HandleMessage(hWnd, message, wParam, lParam);
	}

	return result;
}

void CyMessageProcessor::AddFilter(CyMessageFilter *filter)
{
	_filterList.push_back(filter);
}

void CyMessageProcessor::RemoveFilter(CyMessageFilter *filter)
{
	for (FilterList::iterator i = _filterList.begin();
		i != _filterList.end(); i++)
	{
		if (*i == filter)
		{
			_filterList.erase(i);
			return;
		}
	}

	CY_THROW("Cannot find the message filter in filter list");
}